package com.cykj.shop.controller;

/**
 * @BelongsProject: Cykj-Order-System
 * @BelongsPackage: com.cykj.shop.controller
 * @Author: cwx
 * @CreateTime: 2025/8/25 10:46
 * @Description: 用于用户端首页展示范围内商家
 * @Version: 1.0
 */
import com.cykj.common.core.web.controller.BaseController;
import com.cykj.common.core.web.domain.AjaxResult;
import com.cykj.shop.domain.dto.HotKeywordDTO;
import com.cykj.shop.domain.dto.ShopInfoDTO;
import com.cykj.shop.service.IShopService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 店铺控制器
 */
@RestController
@RequestMapping("/shop_info")
public class CsShopController extends BaseController {

    @Autowired
    private IShopService shopService;

    /**
     * 获取附近商家（多条件筛选）
     */
    @GetMapping("/nearby")
    public AjaxResult getNearbyShops(
            @RequestParam Double longitude,
            @RequestParam Double latitude,
            @RequestParam Double distance,
            @RequestParam(required = false) Integer shopCategory,
            @RequestParam(required = false) String keyword,
            @RequestParam(defaultValue = "0") Double minGrade,
            @RequestParam(defaultValue = "5") Double maxGrade,
            @RequestParam(defaultValue = "20") Integer pageSize) {

        return AjaxResult.success(shopService.getNearbyShops(
                longitude, latitude, distance, shopCategory, keyword, minGrade, maxGrade, pageSize
        ));
    }

    /**
     * 获取店铺分类
     */
    @GetMapping("/categories")
    public AjaxResult getShopCategories() {
        return AjaxResult.success(shopService.getShopCategories());
    }

    /**
     * 获取店铺详情
     */
    @GetMapping("/{id}")
    public AjaxResult getShopDetail(@PathVariable Long id) {
        return AjaxResult.success(shopService.selectShopById(id));
    }

    /**
     * 获取Top10热搜词
     */
    @GetMapping("/hotKeywords")
    public AjaxResult getHotKeywords() {
        List<HotKeywordDTO> hotKeywords = shopService.getHotKeywords();
        return AjaxResult.success(hotKeywords);
    }

    /**
     * 关键词搜索店铺 商品+店铺名 模糊匹配
     */
    @GetMapping("/search")
    public AjaxResult searchShops(
            @RequestParam Double longitude,
            @RequestParam Double latitude,
            @RequestParam(defaultValue = "5") Double distance,
            @RequestParam(required = false) String keyword,
            @RequestParam(defaultValue = "0") Double minGrade,
            @RequestParam(defaultValue = "5") Double maxGrade,
            @RequestParam(defaultValue = "20") Integer pageSize,
            @RequestParam(required = false, defaultValue = "0") Long userId) {

        List<ShopInfoDTO> shops = shopService.searchShops(
                longitude, latitude, distance, keyword, minGrade, maxGrade, pageSize
        );
        return AjaxResult.success(shops);
    }
}